<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--表单组件-->
      <el-dialog :append-to-body=true :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="85px">
          <el-form-item label="北京时间" prop="beijingTime">
            <el-date-picker v-model="form.beijingTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="经度" prop="longitude">
            <el-input v-model="form.longitude" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="纬度" prop="latitude">
            <el-input v-model="form.latitude" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="大地高(H)" prop="geodeticHeight">
            <el-input v-model="form.geodeticHeight" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="靶场(XB)" prop="siteX">
            <el-input v-model="form.siteX" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="靶场(YB)" prop="siteY">
            <el-input v-model="form.siteY" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="靶场(HB)" prop="siteH">
            <el-input v-model="form.siteH" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('beijingTime')" prop="beijingTime" label="北京时间" width=160>
          <template slot-scope="scope">
            <span>{{ parseTimeS(scope.row.beijingTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('longitude')" prop="longitude" label="经度" />
        <el-table-column v-if="columns.visible('latitude')" prop="latitude" label="纬度" />
        <el-table-column v-if="columns.visible('geodeticHeight')" prop="geodeticHeight" label="大地高(H)" />
        <el-table-column v-if="columns.visible('siteX')" prop="siteX" label="靶场(XB)" />
        <el-table-column v-if="columns.visible('siteY')" prop="siteY" label="靶场(YB)" />
        <el-table-column v-if="columns.visible('siteH')" prop="siteH" label="靶场(HB)" />
        <el-table-column v-permission="['admin','daSubtaskData01:edit','daSubtaskData01:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDaSubtaskData01 from '@/api/daSubtaskData01'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '数据01', url: 'api/daSubtaskData01', sort: 'id,desc', crudMethod: { ...crudDaSubtaskData01 }})
const defaultForm = { id: null, daSubtaskId: null, beijingTime: null, longitude: null, latitude: null, geodeticHeight: null, siteX: null, siteY: null, siteH: null, isDelete: null, createUser: null, createDate: null, updateUser: null, updateDate: null }
export default {
  name: 'DaSubtaskData01',
  components: { pagination, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['dept_status'],
  props: {
    data01Data:{
      type: Object,
      // default: function () { return {}} }
      default: () => {}
    },
  },
  created() {
    console.log("sdf",this.data01Data.systemFilename);
  },
  data() {
    return {
      permission: {
        add: ['admin', 'daSubtaskData01:add'],
        edit: ['admin', 'daSubtaskData01:edit'],
        del: ['admin', 'daSubtaskData01:del']
      },
      rules: {
        daSubtaskId: [
          { required: true, message: '设备不能为空', trigger: 'blur' }
        ],
        beijingTime: [
          { required: true, message: '北京时间不能为空', trigger: 'blur' }
        ],
        longitude: [
          { required: true, message: '经度不能为空', trigger: 'blur' }
        ],
        latitude: [
          { required: true, message: '纬度不能为空', trigger: 'blur' }
        ],
        geodeticHeight: [
          { required: true, message: '大地高(H)不能为空', trigger: 'blur' }
        ],
        siteX: [
          { required: true, message: '靶场(XB)不能为空', trigger: 'blur' }
        ],
        siteY: [
          { required: true, message: '靶场(YB)不能为空', trigger: 'blur' }
        ],
        siteH: [
          { required: true, message: '靶场(HB)不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'daSubtaskId', display_name: '设备' }
      ]
    }
  },
  watch: {
    data01Data(){
      this.query.daDataFileSf = this.data01Data.systemFilename;
      this.crud.refresh()
　　}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      query.daDataFileSf = this.data01Data.systemFilename;
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    }
  }
}
</script>